package com.hndct.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

public class GuangDianBaoUtil {
	private static final Logger logger = LoggerFactory.getLogger(GuangDianBaoUtil.class);
	
	//测试环境信息
	private static final String DOMAIN = "http://gdb.jefootoon.com/";
	private static final String APP_ID = "test1";
	private static final String API_KEY = "apikey_test1";
	
	//正式环境信息
	
	
	/**
	 * 凭手机号获取本站用户数据（可实现用户的同步）
	 * @param mobile 手机号，必须
	 * @return
	 */
	public static String getUserInfoByMob(String mobile){
		Map<String,String> param = new HashMap<String,String>();
		param.put("appid", APP_ID);
		param.put("apikey", API_KEY);
		param.put("mob", mobile);
		
		logger.info("【光电宝】getUserInfoByMob，请求参数：{}",mobile);
		String res = HttpClientUtil.doPost(DOMAIN+"Api/OpenApi/getUserInfoByMob", param);
		logger.info("【光电宝】getUserInfoByMob，返回数据：{}",res);
		
		return res;
	}
	
	/**
	 * 获取单个用户积分（电力值） - 单条
	 * @param uid 本系统用户uid,必须
	 * @return 
	 */
	public static String creditFind(String uid){
		Map<String,String> param = new HashMap<String,String>();
		param.put("appid", APP_ID);
		param.put("apikey", API_KEY);
		param.put("uid", uid);
		
		logger.info("【光电宝】creditFind，请求参数：{}",uid);
		String res = HttpClientUtil.doPost(DOMAIN+"Api/OpenApi/creditFind", param);
		logger.info("【光电宝】creditFind，返回数据：{}",res);
		
		return res;
	}
	
	/**
	 * 获取多个用户积分（电力值） - 多条（单次最多查询100条）
	 * @param uids 查询用户uid, 必须。最多100个， 多个用逗号分隔，如 1,2,3
	 * @return
	 */
	public static String creditSelect(String uids){
		Map<String,String> param = new HashMap<String,String>();
		param.put("appid", APP_ID);
		param.put("apikey", API_KEY);
		param.put("uids", uids);
		
		logger.info("【光电宝】creditSelect，请求参数：{}",uids);
		String res = HttpClientUtil.doPost(DOMAIN+"Api/OpenApi/creditSelect", param);
		logger.info("【光电宝】creditSelect，返回数据：{}",res);
		
		return res;
	}
	
	public static String userPanelsSelect(String uids){
		Map<String,String> param = new HashMap<String,String>();
		param.put("appid", APP_ID);
		param.put("apikey", API_KEY);
		param.put("uids", uids);
		
		logger.info("【光电宝】userPanelsSelect，请求参数：{}",uids);
		String res = HttpClientUtil.doPost(DOMAIN+"Api/OpenApi/userPanelsSelect", param);
		logger.info("【光电宝】userPanelsSelect，返回数据：{}",res);
		
		return res;
	}
	
//	public static void main(String[] args) {
//		System.out.println(getUserInfoByMob("123456"));
//		System.out.println(creditFind("1"));
//		System.out.println(creditSelect("1,2,3"));
//		System.out.println(userPanelsSelect("2,1"));
//	}
	
}
